package com.gouwudai.gobbs.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;

import com.gouwudai.gobbs.common.IPageList;
import com.gouwudai.gobbs.dao.IContentFilterDAO;
import com.gouwudai.gobbs.pojo.TbbsContentFilter;
import com.litt.core.common.Utility;

/**
 * 
 * <pre>
 *  Title:内容过滤DAO
 *  Description: TODO  
 * </pre>
 * 
 * @author <a href="mailto:littcai@hotmail.com">空心大白菜</a>
 * @date 2007-3-29
 * @version 1.0
 * <pre>
 * 修改记录
 *    修改后版本:     修改人：  修改日期:     修改内容: 
 * </pre>
 */
public class ContentFilterDAOImpl extends BaseDAOImpl implements IContentFilterDAO 
{
	private static final Logger logger = Logger.getLogger(ContentFilterDAOImpl.class);	
	private static final String BUSI_NAME = "内容过滤";	
	
	/**
	 * @param tbbsContentFilter
	 */
	public void save(TbbsContentFilter tbbsContentFilter)
	{
        super.saveObject(tbbsContentFilter);		
	}
	
	/**
	 * @param id
	 * @return
	 */
	public TbbsContentFilter load(Integer id)
	{
		return (TbbsContentFilter)super.loadObject(TbbsContentFilter.class, id);
	}   
    
    /**
	 * @param tbbsContentFilter
	 */
    public void update(TbbsContentFilter tbbsContentFilter)
    {
        StringBuilder hql = new StringBuilder();
        hql.append("update TbbsContentFilter set sourceStr=?");
        hql.append(", replaceStr=?");        
        hql.append(" where cfId=?");
        super.updateObject(hql.toString(), new Object[]{
        	tbbsContentFilter.getSourceStr(),
        	tbbsContentFilter.getReplaceStr(),
        	tbbsContentFilter.getCfId()});

    }

    /**
	 * @param cfId
	 */
    public void delete(Integer cfId)
    {
        super.deleteObject(TbbsContentFilter.class.getName(),"cfId",cfId);
    }
    
    /**
	 * @param cfIds
	 */
    public void deleteBatch(String cfIds)
    {
        super.deleteObjects(TbbsContentFilter.class.getName(),"cfId",cfIds);
    }    

    /**
	 * @return
	 */
    public List listAll()
    {       
    	return  super.listAll("from TbbsContentFilter");
    }
    
    /**
	 * @param filterType
	 * @return
	 */
    public List listByType(int filterType)
    {       
    	String listSql = "from TbbsContentFilter where filterType=0 or filterType="+filterType;
    	return  super.listAll(listSql);
    }    
    
    /**
	 * @param pageIndex
	 * @param pageSize
	 * @param sort 排序字段
	 * @return
	 */
    public IPageList listPage(int pageIndex,int pageSize,String sort)
    {       
    	StringBuffer listSql = new StringBuffer("SELECT A.*,B.DICT_CONTENT AS FILTER_TYPE_NAME FROM TbbsContentFilter A,TbbsDictParam B WHERE B.DICT_TYPE='S001' AND A.FILTER_TYPE=B.DICT_VALUE");
    	if(!Utility.isEmpty(sort))
            listSql.append(sort);
        return super.listSqlPage(listSql.toString(),pageIndex,pageSize);
    }    
}
